package com.ikas.ai.server.module.morningpaper.model.elements;

import com.ikas.ai.server.module.morningpaper.consts.MorningPaperElementPriorities;
import com.ikas.ai.server.module.morningpaper.consts.MorningPaperNormalVariableNames;
import com.ikas.ai.server.module.morningpaper.exception.MorningPaperException;
import com.ikas.ai.server.module.morningpaper.model.dto.MorningPaperVariablesDto;
import com.ikas.ai.server.module.morningpaper.model.po.MorningPaperVariablesPo;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 机组优先权，分别为1-2-3-4，2-3-4-1，3-4-1-2，4-1-3-2，以此为顺序，取前一日结果，并获得递进的下一个结果
 */
@Component
@Lazy
public class ElementMachinePriority extends MorningPaperTopElement {

    public static final String ONE_TWO_THREE_FOUR = "1-2-3-4";
    public static final String TWO_THREE_FOUR_ONE = "2-3-4-1";
    public static final String THREE_FOUR_ONE_TWO = "3-4-1-2";
    public static final String FOUR_ONE_TWO_THREE = "4-1-2-3";

    protected String MORNING_PAPER_VARIABLE_NAME = MorningPaperNormalVariableNames.machinePriority.name();

    @Override
    public String getMorningPaperVariableName() {
        return MORNING_PAPER_VARIABLE_NAME;
    }

    protected MorningPaperElementPriorities PRIORITY = MorningPaperElementPriorities.FIRST_PRIORITY;

    @Override
    public MorningPaperElementPriorities getPriority() {
        return PRIORITY;
    }

    @Override
    public MorningPaperVariablesDto render(MorningPaperVariablesDto mv, Map<String, MorningPaperVariablesPo> variablesPoMap, Map<String, Object> transmitMap) {
        super.render(mv, variablesPoMap, transmitMap);
        String machinePriority = getValueFromVariableTable(this, String.class);
        switch (machinePriority) {
            case ONE_TWO_THREE_FOUR:
                machinePriority = TWO_THREE_FOUR_ONE;
                break;
            case TWO_THREE_FOUR_ONE:
                machinePriority = THREE_FOUR_ONE_TWO;
                break;
            case THREE_FOUR_ONE_TWO:
                machinePriority = FOUR_ONE_TWO_THREE;
                break;
            case FOUR_ONE_TWO_THREE:
                machinePriority = ONE_TWO_THREE_FOUR;
                break;
            default:
                throw new MorningPaperException(MorningPaperException.machinePriorityNotCorrect);
        }
        mv.setMachinePriority(machinePriority);
        return mv;
    }

}
